(function($) {

    if (!$.validator) {
        throw new Error("Not found the the jquery validate, can't extend it.");
    }

    $.validator.prototype.clear = function(ignore) {
        this.resetForm();
        var i, elements;
        if (this.settings.clearHighlight) {
            for (i = 0, elements = this.elements(ignore); elements[i]; i++) {
                this.settings.clearHighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass);
            }
        }
    };

    $.validator.prototype.elements = function(ignore) {
        var validator = this, rulesCache = {};
        return $(this.currentForm).find("input, select, textarea").not(":submit, :reset, :image, [disabled], .iCheck-helper").not(
                ignore || this.settings.ignore).filter(function() {
            if (!this.name && validator.settings.debug && window.console) {
                //console.error("%o has no name assigned", this);
            }
            if (this.name in rulesCache || !validator.objectLength($(this).rules())) {
                return false;
            }
            rulesCache[this.name] = true;
            return true;
        });
    };

    $.validator.defaults.clearHighlight = function(element, errorClass, validClass) {
        if (element.type === "radio") {
            this.findByName(element.name).removeClass(errorClass).removeClass(validClass).parent().removeClass('state-success state-error');
        } else {
            $(element).removeClass(errorClass).removeClass(validClass).parent().removeClass('state-success state-error');
        }
    };

})(jQuery);